#include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
class Solution
{
public:
    int add(int a, int b)
    {
        // return a == 0 ? b : add ((a & b) << 1, a ^ b);
        return (0 == a || 0 == b) ? a ^ b : add(a ^ b, (a & b) << 1);
    }

    int add_2(int a, int b)
    {
        while (b)
        {
            int temp = a ^ b;
            b = (a & b) << 1;
            a = temp;
        }
        return a;
    }
};
int main()
{
    Solution s;
    vector<vector<int>> nums = {{1, 1}, {1, 0}, {0, 0}, {13, 9}, {1, -1}, {INT32_MIN, INT32_MAX}, {INT32_MIN, 1}, {INT32_MAX, -1}, {-8, -9}};
    for (int i = 0; i < nums.size(); i++)
    {
        int a = nums[i][0], b = nums[i][1];
        cout << a << " + " << b << " = " << s.add_2(a, b) << endl;
    }

    system("pause");
    return 0;
}
